<?php
class Forget extends CI_Controller {
	public function __construct() {
		parent::__construct ();
		$this->load->helper ( array (
				'form',
				'url' 
		) );
	}
	
	/**
	 * 忘记密码页面显示
	 */
	public function index() {
		$this->load->view ( 'forget' );
	}
	
	// 保存新密码
	public function update_pwd() {
		if (empty($_SESSION ['code'])) {
			exit ( $this->common->alert_msg_goback ( '验证码错误' ) );
		}
		
		if ($_SESSION ['code'] != $_POST ['yzm']) {
			exit ( $this->common->alert_msg_goback ( '验证码错误' ) );
		}
		
		if(empty($_POST['mobile'])){
			exit ( $this->common->alert_msg_goback ( '手机号不能为空' ) );
		}
		
		$info = $this->user->get_user_mobile($_POST['mobile']);
		//var_dump($info);exit;
		if(empty($info)){
			exit ( $this->common->alert_msg_goback ( '此手机号未注册过' ) );
		}

		$this->load->model ( 'user_model' );
		$res = $this->user_model->update_pwd_by_mobile ( $_POST ['mobile'] ,$_POST['pwd_type']);
		
		if (! empty ( $res )) {
			exit ( $this->common->alert_msg_url ( '找回成功', site_url ( 'login' ) ) );
		} else {
			exit ( $this->common->alert_msg_goback ( '找回失败' ) );
		}
	}
}